{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# %load \"~/sympy_work_code/environment.py\"\n",
    "from sympy import *\n",
    "from sympy.abc import x,y,z,t,k,l,n,m,p,q\n",
    "from sympy.calculus.util import *\n",
    "from sympy.stats import *\n",
    "\n",
    "from sys import path\n",
    "path.append(\"/home/huang/Documents/packaging_tutorial/src\")\n",
    "\n",
    "%load_ext autoreload \n",
    "%autoreload 1\n",
    "\n",
    "%aimport basic_package.utils\n",
    "%aimport function_calculator_package.extreme_points\n",
    "%aimport quadratic_function.utils\n",
    "%aimport quadratic_function.hyperbola\n",
    "%aimport quadratic_function.utils\n",
    "\n",
    "from basic_package.utils import *\n",
    "from function_calculator_package.extreme_points import *\n",
    "from quadratic_function.quadraticfunction import QuadraticFunction\n",
    "from quadratic_function.hyperbola import Hyperbola\n",
    "from quadratic_function.utils import line_and_quadratic\n",
    "\n",
    "%aimport solver.utils\n",
    "from solver.utils import solve_univariate_inequalities\n",
    "\n",
    "%aimport function_calculator_package.utils \n",
    "from function_calculator_package.utils import function_is_odd\n",
    "\n",
    "%aimport geometry3D.frustum\n",
    "%aimport geometry3D.prism\n",
    "%aimport geometry3D.pyramid\n",
    "from geometry3D.frustum import Frustum\n",
    "from geometry3D.prism import Prism,Cube\n",
    "from geometry3D.pyramid import Pyramid,Cone,Tetrahedron\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from sympy import *\n",
    "from sympy.abc import x,y,z,t,k,l,n,m,p,q\n",
    "from sympy.calculus.util import *\n",
    "from sympy.stats import *\n",
    "\n",
    "from sys import path\n",
    "path.append(\"/home/huang/Documents/packaging_tutorial/src\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "\n",
    "%load_ext autoreload \n",
    "%autoreload 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "%aimport basic_package.utils\n",
    "%aimport function_calculator_package.extreme_points\n",
    "%aimport quadratic_function.utils\n",
    "%aimport quadratic_function.hyperbola\n",
    "%aimport quadratic_function.utils\n",
    "\n",
    "from basic_package.utils import *\n",
    "from function_calculator_package.extreme_points import *\n",
    "from quadratic_function.quadraticfunction import QuadraticFunction\n",
    "from quadratic_function.hyperbola import Hyperbola\n",
    "from quadratic_function.utils import line_and_quadratic\n",
    "\n",
    "%aimport solver.utils\n",
    "from solver.utils import solve_univariate_inequalities\n",
    "\n",
    "%aimport function_calculator_package.utils \n",
    "from function_calculator_package.utils import function_is_odd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x/(x-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{x}{x - 1}$"
      ],
      "text/plain": [
       "x/(x - 1)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "f=lambdify(x,expr-log(x,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.optimize import fsolve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.88747485])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fsolve(f,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.5])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fsolve(f,1/3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "c=Circle(Point(3/S(2),2),sqrt(5)/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Point(2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1=Circle(Point(1,1),3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "59.60464477539062"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "64/(1.024)**3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\sqrt{174}$"
      ],
      "text/plain": [
       "sqrt(174)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sqrt(174)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle -28$"
      ],
      "text/plain": [
       "-28"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "binomial(8,6)-binomial(8,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{11: 1, 17: 1, 61: 1, 113: 1}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factorint(6**8-5**8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 0.6 \\sqrt{2}$"
      ],
      "text/plain": [
       "0.6*sqrt(2)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.6*sqrt(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "pyramid=Pyramid(sqrt(2),RegularPolygon((0,0),1,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "A,B,C,D=pyramid.vertices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\sqrt{3}$"
      ],
      "text/plain": [
       "sqrt(3)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.distance(B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "M=(A+C)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "N=(A+D)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\operatorname{acos}{\\left(- \\frac{1}{6} \\right)}$"
      ],
      "text/plain": [
       "acos(-1/6)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Line(B,M).angle_between(Line(C,N))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\operatorname{acos}{\\left(- \\frac{1}{6} \\right)}$"
      ],
      "text/plain": [
       "acos(-1/6)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Abs(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "cube=Cube(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left( \\operatorname{Point3D}\\left(0, 0, 0\\right), \\  \\operatorname{Point3D}\\left(1, 0, 0\\right), \\  \\operatorname{Point3D}\\left(1, 1, 0\\right), \\  \\operatorname{Point3D}\\left(0, 1, 0\\right), \\  \\operatorname{Point3D}\\left(0, 0, 1\\right), \\  \\operatorname{Point3D}\\left(1, 0, 1\\right), \\  \\operatorname{Point3D}\\left(1, 1, 1\\right), \\  \\operatorname{Point3D}\\left(0, 1, 1\\right)\\right)$"
      ],
      "text/plain": [
       "(Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 1, 0), Point3D(0, 1, 0), Point3D(0, 0, 1), Point3D(1, 0, 1), Point3D(1, 1, 1), Point3D(0, 1, 1))"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cube.vertices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "A,B,C,D,A1,B1,C1,D1=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "E=(A1+B1)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "F=(B+B1)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "G=(B+C)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "H=(C+D)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "I=(D+D1)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "J=(A1+D1)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Polygon3D' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_8389/123493356.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpoly3\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mPolygon3D\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mE\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mF\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mG\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mH\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mI\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mJ\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'Polygon3D' is not defined"
     ]
    }
   ],
   "source": [
    "poly3=Polygon3D(E,F,G,H,I,J)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "m=Matrix([E,F,G,H,I,J])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} & 0 & 1\\\\1 & 0 & \\frac{1}{2}\\\\1 & \\frac{1}{2} & 0\\\\\\frac{1}{2} & 1 & 0\\\\0 & 1 & \\frac{1}{2}\\\\0 & \\frac{1}{2} & 1\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[1/2,   0,   1],\n",
       "[  1,   0, 1/2],\n",
       "[  1, 1/2,   0],\n",
       "[1/2,   1,   0],\n",
       "[  0,   1, 1/2],\n",
       "[  0, 1/2,   1]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{81}{8}$"
      ],
      "text/plain": [
       "81/8"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "det(m.T*m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{9 \\sqrt{2}}{4}$"
      ],
      "text/plain": [
       "9*sqrt(2)/4"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sqrt(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{3 \\sqrt{6}}{2}$"
      ],
      "text/plain": [
       "3*sqrt(6)/2"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_/(sqrt(3)/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "poly=RegularPolygon(Point(0,0),1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{3 \\sqrt{3}}{2}$"
      ],
      "text/plain": [
       "3*sqrt(3)/2"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly.area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "A,B,C,D,E,F=poly.vertices\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "m=Matrix([A,B,C,D,E,F])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}1 & 0\\\\\\frac{1}{2} & \\frac{\\sqrt{3}}{2}\\\\- \\frac{1}{2} & \\frac{\\sqrt{3}}{2}\\\\-1 & 0\\\\- \\frac{1}{2} & - \\frac{\\sqrt{3}}{2}\\\\\\frac{1}{2} & - \\frac{\\sqrt{3}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[   1,          0],\n",
       "[ 1/2,  sqrt(3)/2],\n",
       "[-1/2,  sqrt(3)/2],\n",
       "[  -1,          0],\n",
       "[-1/2, -sqrt(3)/2],\n",
       "[ 1/2, -sqrt(3)/2]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 9$"
      ],
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "det(m.T*m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 3$"
      ],
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sqrt(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}1 & 0\\\\\\frac{1}{2} & \\frac{\\sqrt{3}}{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[  1,         0],\n",
       "[1/2, sqrt(3)/2]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[0:2,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5*sqrt(3)/2\n"
     ]
    }
   ],
   "source": [
    "sum=0\n",
    "for i in range(5):\n",
    "    sum+=det(m[i:i+2,:])\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{2} & - \\frac{\\sqrt{3}}{2}\\\\1 & 0\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[1/2, -sqrt(3)/2],\n",
       "[  1,          0]])"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Matrix([m[5,:],m[0,:]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\sqrt{3}}{2}$"
      ],
      "text/plain": [
       "sqrt(3)/2"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "det(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
